<template>
	<view>
		<view class="uni-header">
			<view class="uni-group">
				<view class="uni-title">订单管理</view>
				<view class="uni-sub-title">/订单列表</view>
			</view>

			<view class="uni-group">
				<view class="select" style="width:200px;" >
					<uni-datetime-picker type="datetimerange" 
						:clear-icon="true" v-model="single" @change="datetimePicker" 
						return-type="timestamp"
						:start="Date.now() - ((1000*60 * 60)*24*30 )"
						:end="Date.now()"
						rangeSeparator="至"
					/>
				</view>
				<input class="uni-search" type="text" v-model="query" @confirm="search" placeholder="请输入订单号或手机号" />
				<button class="uni-button" type="default" size="mini" @click="search">搜索</button>

			</view>
		</view>
		<!-- <button type="primary" @click="onclick" >火箭发射</button> -->


		<view class="uni-container">
			<unicloud-db ref="udb" :collection="collectionList"
				field="provider,shop_id,orders_source,service_text,pay_status,refund,group_buying_price,refund_total_price,status,pay_type,service_type,service_time,reality_service_time,serial_number,cancel_order,rider,type,reminder,order_no,delivery_price,timeOut,deduct_delivery_price,total_price,pack_price,preferential,user_id,nickname,notes,address,client_ip,openid,description,err_msg,total_fee,refund_fee,refund_count,refund_list,is_receive_order,provider_appid,appid,user_order_success,custom,original_data,create_date,pay_date,notify_date,cancel_date,is_comment,stat_data"
				:where="orderWhere" page-data="replace" :orderby="orderby" :getcount="true" :page-size="options.pageSize"
				:page-current="options.pageCurrent" v-slot:default="{data,pagination,loading,error,options}"
				:options="options" loadtime="manual" @load="onqueryload">
				<uni-table ref="table" :loading="loading" :emptyText="data.length || '暂无更多数据'" stripe type="selection"
					@selection-change="selectionChange">
					<uni-tr>
						<uni-th align="center">
							#
						</uni-th>
						<uni-th align="center"  >
							商铺名称
						</uni-th>
						<uni-th align="center" sortable @sort-change="sortChange($event, 'rider')">
							骑手信息
						</uni-th>
						<uni-th align="center">
							收货人
						</uni-th>

						<uni-th align="center" filter-type="select" :filter-data="optionsStatus"
							@filter-change="onFilter( $event ,'status')">
							订单状态
						</uni-th>
						<uni-th align="center">
							总金额
						</uni-th>
						<uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'order_no')" sortable
							@sort-change="sortChange($event, 'order_no')">
							订单号
						</uni-th>
						<uni-th align="center" filter-type="select" :filter-data="optionType"
							@filter-change="onFilter( $event ,'type')">
							订单类型
						</uni-th>
						<uni-th align="center" width="250">
							收货信息
						</uni-th>
						<uni-th align="center">
							下单平台
						</uni-th>
						<uni-th align="center">配送费</uni-th>
						<uni-th align="center">打包费</uni-th>
						<uni-th align="center" width="130">备注</uni-th>
						<uni-th align="center">
							支付时间
						</uni-th>
						<uni-th align="center">
							创建时间
						</uni-th>
						<uni-th width="520" align="center">操作</uni-th>
					</uni-tr>
					<uni-tr v-for="(item,index) in data" :key="index">
						<!-- 编号 -->
						<uni-td align="center" style="font-weight:bold">
							{{item.serial_number}}
						</uni-td>
						<!-- 店铺 -->
						<uni-td align="center">
							<view v-for="items in item.shop_id" class="titleApp">
								<navigator :url="`/pages/shop/shop/shop-info?_uid=${item.shop_id[0]._id}`">
									<text class="titleApp">
										{{items.title}}
									</text>
								</navigator>
							</view>
						</uni-td>
						<!-- 骑手 -->
						<uni-td align="center">
							<view>
								<view v-if="item.rider" style="display: flex;justify-content: center;">
									<navigator v-if="isPower(['admin','administrators','region'])" :url="`/pages/rider/rider_users/detail?_uid=${item.rider.user_id}`">
										<text> {{item.rider.nickname}} </text>
									</navigator>
									<text v-else > {{item.rider.nickname}} </text>
									-
									<text class="telApp">
										{{ mobileReconfiguration(item.rider.mobile)}}
									</text>
								</view>
								<text v-else>
									暂未分配
								</text>
							</view>
						</uni-td>
						<!-- 用户 -->
						<uni-td align="center">
							<view v-if="IsAdddress(item.address)" style="display: flex;justify-content: center;">
								<navigator  :url="`/pages/system/user/detail?id=${item.address.user_id}`">
									<text>{{item.address?item.address.name:''}} </text>
								</navigator>
								<text class="telApp">
									- <text>
										{{(item.address?mobileReconfiguration(item.address.phone):'暂无')}}
									</text>
								</text>
							</view>

						</uni-td>
						<!-- 状态 -->
						<uni-td align="center" :style="`color:${ onStatus(item.status.value) }`">
							<text  >
								<text v-if="item.refund &&  item.status.value!=9" >
									{{item.status.text}}
								</text>
								<text  v-else-if="item.status.value<=5"  >
									{{item.status.text}}
								</text>
								<text v-else-if="!item.refund" >
									{{item.status.text}}
								</text>
							</text>
							<text v-if="item.refund && item.status.value!=5" style="color:#999" >
								&nbsp; {{item.refund?item.refund.text: ''}}
							</text>
						</uni-td>
						<!-- 金额 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.total_fee/100}}
							</text>
						</uni-td>
						<!-- 单号 -->
						<uni-td align="center">
							{{item.order_no}}
						</uni-td>
						<!-- 类型 -->
						<uni-td align="center">
							{{item.type==2?'到店就餐':item.service_text=='预约时间送达'?'按预约时间送达':'外卖配送'}}
						</uni-td>
						<uni-td align="center">
							<view class="pages_content">
								{{item.address?item.address.title+' - '+ item.address.address_detail :''}}
							</view>
						</uni-td>
						<!-- 下单来源 -->
						<uni-td align="center">
							{{item.orders_source?item.orders_source : '暂无信息'}}
						</uni-td>
						<!-- 收取客户的配送费 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.delivery_price/100}}
							</text>
						</uni-td>
						<!-- 打包费 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.pack_price/100}}
							</text>
						</uni-td>
						<!-- 备注 -->
						<uni-td align="center">
							<view class="pages_content ">
								{{item.notes}}
							</view>
						</uni-td>
						<!-- 支付时间 -->
						<uni-td align="center">
							<uni-dateformat :date="item.pay_date"></uni-dateformat>
						</uni-td>
						<uni-td align="center">
							<uni-dateformat :date="item.create_date.time_stamp"></uni-dateformat>
						</uni-td>
						<uni-td align="center">
							<view class="uni-group">
								<button @click="navigateTo('/pages/order/uni-pay-orders/detail?id='+item.order_no, false)" class="uni-button" size="mini"
									type="">
									详 情
								</button>
								<button @click="onOpention(item.shop_id,1)" class="uni-button" size="mini" type="primary">
									语音提醒
								</button>
								<button @click="onOpention(item,3)" class="uni-button" size="mini" type="primary">
									更换骑手
								</button>
								<button :disabled="!isPower(['admin'])" @click="onOpention(item,4)" class="uni-button"
									size="mini" type="warn">
									修改状态
								</button>
								<button size="mini" type="warn" @click="onOpention(item,2)" :disabled="!isPower(['admin'])" v-if="!item.refund" >
									取消订单
								</button>
								<button size="mini" v-else type="warn" @click="onOpention(item,2)" :disabled="!isPower(['admin'])">
									同意退款
								</button>
							</view>
						</uni-td>

					</uni-tr>
				</uni-table>
				<view class="uni-pagination-box">
					<uni-pagination show-icon :page-size="pagination.size" v-model="pagination.current"
						:total="pagination.count" @change="onPageChanged" />
				</view>
			</unicloud-db>
		</view>
		<!-- 修改状态 -->
		<uni-popup ref="showUpdateStatus" type="center" backgroundColor="#fff">
			<view class="popup">
				<view class="title">
					修改状态
				</view>
				<view class="body">
					<view>
						<text>店铺：</text>
						<text class="titleApp">
							{{temp_uid.shop_id[0].title}}
						</text>
					</view>
					<view>
						<text>订单号：</text>
						<text class="">
							{{temp_uid.order_no}}
						</text>
					</view>
					<view class="maxbox" style="min-height:200px;">
						<uni-data-select v-model="selectStatus" :localdata="rangeStatus"></uni-data-select>
					</view>
					<view style="margin:20px 0;">
						<button @click="updateStatus()" class="uni-button" size="mini" type="primary">
							确认修改
						</button>
						<button @click="this.$refs.showUpdateStatus.close()" class="uni-button" size="mini" type=" ">
							取消
						</button>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 更换骑手 -->
		<uni-popup ref="showUpdateRider" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="title">
					更换骑手
				</view>
				<view class="body">
					<view>
						<text>店铺：</text>
						<text class="titleApp">
							{{temp_uid.shop_id[0].title}}
						</text>
					</view>
					<view>
						<text>
							当前骑手：
						</text>
						<text class="titleApp">
							{{temp_uid.rider?temp_uid.rider.nickname:'暂无骑手'}}
						</text>
					</view>
					<view class="titleApp" style="font-size:14px">
						更换为:
						<text>
							{{ rangeRider[selectRider].text }}
						</text>
					</view>
					<view class="maxbox">
						<view class="grid">
							<view class="item_box" v-for="(item,index) in rangeRider" @click="handleItemClick(item,index)"
								:class="index===selectRider?'item_boxTow':''">
								<view>
									<image class="image" :src="item.avatar+ '?x-oss-process=image/resize,m_fixed,h_200,w_200'"
										mode="widthFix"></image>
								</view>
								<view class="label">
									{{item.text}}
								</view>
								<view class="label">
									{{item.order_number}} 单
								</view>
							</view>
						</view>
					</view>
					<view style="margin:20px 0;">
						<button @click="updateRider()" class="uni-button" size="mini" type="primary">
							确认更换
						</button>
						<button @click="this.$refs.showUpdateRider.close()" class="uni-button" size="mini" type=" ">
							取消
						</button>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 语音提醒 -->
		<uni-popup ref="showStatus" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="titleApp">
					选择语音催餐
				</view>
				<view class="body">
					<view style="margin:20rpx 0">
						Tel: <text style="color:#ff6600">{{mobileReconfiguration(temp_uid)}}</text>
					</view>
					<view style="margin:100rpx 0">
						"语音催接单"指的是通过语音方式来催促商家或者服务提供方尽快接受订单。
					</view>
					<button @click="eventVoice" class="uni-button" size="mini" type="primary">
						催 接 单
					</button>
				</view>
			</view>
		</uni-popup>
		<!-- 取消订单提醒 -->
		<uni-popup ref="showOrderOut" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="titleApp">
					取消当前订单
				</view>
				<view class="body">
					<view style="margin:20rpx 0">
						<view style="margin:20rpx 0;color:#565656">
							确认取消订单后，金额将会如数退还给用户。
						</view>
						<view class="titleApp">
							须知！
						</view>
						<view class="labelApp">
							取消订单:只能取消未完成订单和未取消订单，取消后包括商家账单/金额也会更改，订单金额也会如数奉还给用户。在后台取消订单不会扣除订单的20%计算到商家头上。
							<view style="font-weight:bold;color:#ff3300;margin:10px 0">
								请与上级领导落实准确，切勿私自取消订单，否则后果自负!
							</view>
						</view>
					</view>
					<button @click="toRefund" :disabled="temp_uid.status.value > 4" class="uni-button" size="mini" type="warn">
						取消订单
					</button>
					<button @click="this.$refs.showOrderOut.close()" class="uni-button" size="mini" type="">
						取消
					</button>
				</view>
			</view>
		</uni-popup>

	</view>
	<uni-pay ref="pay" :adpid="adpid" height="70vh" return-url="/pages/index/index" logo="/static/logo.png"></uni-pay>

</template>

<script>
	import Util from "@/js_sdk/validator/util.js"
	import {filterToWhere} from '@/js_sdk/validator/orders.js';

	import error from "../../../store/modules/error";
	import {updateRider,updateStatus} from "@/pages/order/uni-pay-orders/order.js"
	const PUSH = uniCloud.importObject("push", {
		customUI: true
	})
	const order = uniCloud.importObject("order", {
		customUI: true
	})
	const db = uniCloud.database()
	const global = uniCloud.importObject("global", {
		customUI: true
	})
	// 表查询配置
	const dbOrderBy = '' // 排序字段
	const dbSearchFields = [] // 模糊搜索字段，支持模糊搜索的字段列表。联表查询格式: 主表字段名.副表字段名，例如用户表关联角色表 role.role_name
	// 分页配置
	const pageSize = 20
	const pageCurrent = 1
	const orderByMapping = {
		"ascending": "asc",
		"descending": "desc"
	}
	let where_uid = null;
	export default {
		data() {
			return {
				//a 日期下拉框
				selectTimeVal: 0,
				rangeStatus: [
					{value: 0,text: "待支付"}, 
					{value: 1,text: "待接单"},
					{value: 2,text: "已接单"},
					{value: 3,text: "骑手已到店"},
					{value: 4,text: "骑手已取餐"},
					{value: 5,text: "订单完成"},
					{value: 9,text: "管理员取消"},
				],
				// 更换骑手
				tempRider:{},
				selectRider: 0,
				rangeRider:[],
				selectStatus: 0,
				optionsStatus: [
					{value: 0,text: "有效订单"},
					{value: 1,text: "全部订单"},
					{value: 2,text: "正在进行中"},
					{value: 3,text: "已完成订单"},
					{value: 4,text: "已取消订单"}
				],
				optionType:[
					{value:0,text: "外卖配送"},
					{value:1,text: "预约送达"},
					{value:2,text: "到店就餐"}
				],
				optionShopTitle:[
					{ "value": "", "text": "全部" },
					{ "value": "左营", "text": "左营镇" },
					{ "value": "箕山", "text": "箕山镇" },
					{ "value": "旧城", "text": "旧城镇" },
					{ "value": "郑营", "text": "郑营镇" },
					{ "value": "李进士堂", "text": "李进士堂" },
					{ "value": "凤凰", "text": "凤凰镇" },
					{ "value": "什集", "text": "什集镇" },
					{ "value": "临濮", "text": "临濮镇" },
					{ "value": "富春", "text": "富春镇" }
				],
				temp_uid: null,
				collectionList: [
					db.collection('orders').orderBy("pay_date desc").getTemp(),
					db.collection('shop').field("_id,title,tel").getTemp({
						getOne: true
					})
				],
				query: '',
				orderWhere: {
					$or:[
						{"status.value": db.command.gte(1)}
					]
				},
				orderby: dbOrderBy,
				orderByFieldName: "",
				selectedIndexs: [],
				options: {
					pageSize,
					pageCurrent,
					filterData: {
						"provider_localdata": [{"text": "微信支付","value": "wxpay"},
							{"text": "支付宝","value": "alipay"},
							{"text": "苹果应用内支付","value": "appleiap"}
						],
						"pay_status_localdata": [{"text": "未支付","value": 0},
							{"text": "已支付","value": 1},
							{"text": "已部分退款","value": 2},
							{"text": "已全额退款","value": 3}
						],
						"rate_localdata": [{"text": "好评","value": 1},
							{"text": "中评","value": 2},
							{"text": "差评","value": 3}
						]
					},
				},
				imageStyles: {
					width: 64,
					height: 64
				},
				exportExcel: {
					"filename": "orders.xls",
					"type": "xls",
					"fields": {
						"支付供应商": "provider",
						"订单状态": "status",
						"团派优惠金额": "group_buying_price",
						"已退款总额度": "refund_total_price",
						"订单支付类型": "pay_type",
						"配送类型，外卖配送或到店就餐": "service_type",
						"预计送达时间": "service_time",
						"实际送达时间": "reality_service_time",
						"今日订单编号": "serial_number",
						"是否已申请取消订单": "cancel_order",
						"骑手信息": "rider",
						"订单类型": "type",
						"是否已催单": "reminder",
						"业务系统订单号": "order_no",
						"是否超时": "timeOut",
						"平台扣除配送费": "deduct_delivery_price",
						"打包费": "pack_price",
						"平台减免金额": "preferential",
						"用户ID": "user_id",
						"用户昵称": "nickname",
						"备注": "notes",
						"收货人信息": "address",
						"客户端IP": "client_ip",
						"openid": "openid",
						"支付描述": "description",
						"支付失败原因": "err_msg",
						"订单总金额": "total_fee",
						"订单总退款金额": "refund_fee",
						"当前退款笔数": "refund_count",
						"退款详情": "refund_list",
						"是否接单，默认为true": "is_receive_order",
						"开放平台appid": "provider_appid",
						"DCloud AppId": "appid",
						"回调状态": "user_order_success",
						"自定义数据": "custom",
						"异步通知原始数据": "original_data",
						"下单时间": "create_date",
						"支付时间": "pay_date",
						"异步通知时间": "notify_date",
						"取消时间": "cancel_date",
						"是否已平价": "is_comment",
						"uni统计相关数据": "stat_data"
					}
				},
				exportExcelData: []
			}
		},
		onLoad(e) {
			if (e._uid) {
				this.orderWhere = {
					"shop_id._id": e._uid,
					"status.value": db.command.gte(1)
				}
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			}else if(e.orderNo){
				this.orderWhere = {
					"order_no": e.orderNo
				}
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			} else {
				where_uid = db.command.elemMatch({})
			}
		},
		onReady() {
			this.$refs.udb.loadData()
		},
		methods: {
			getRider(){
				let Field = "avatar,name as text,order_number,mobile,_id"
				db.collection("rider_users").limit(999).where({is_online:true,status:true,"examine_status.value":1}).field(Field).get({getOne:false,customUI:true}).then( res => {
					let Data = res.result.data
					let tempData = Data.map((item ,index)=> {
						item.value = index
						return item
					})
					this.rangeRider = tempData
				})
			},
			// 筛选
			onFilter(event, filter) {
				let result = filterToWhere(event.filter, filter)
				 // console.log(result);
				this.orderWhere.$or = [...result]
				// console.log(this.orderWhere);
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
			/**
			 * 商家催单
			 * @param type -0.催接单、1催出餐  */
			eventVoice(type) {
				uni.showLoading({
					title: '正在呼出···'
				})
				let http = 'https://api.yipaidaojia.com/index.php/api/aliyun_voice'
				let data = {tel: this.temp_uid,token: '86f24d4bf67694706a347dc36f3365c0'}
				uni.request({method: 'POST',url: http,data: data}).then(res => {
					uni.hideLoading()
					this.$refs.showStatus.close()
					uni.showToast({title: '呼出成功'})
				})
			},
			/**
				取消订单-退款
			*/
			async toRefund() {
				let that = this;
				const orderNo = this.temp_uid.order_no
				uni.showModal({title: '提示',content: '确定要取消订单吗？',}).then(async res => {
					if ( !res.confirm ) return
					const db = uniCloud.database()
					this.$refs.showOrderOut.close()
					uni.showLoading({title:'退款中',mask:true})
					let refund = uniCloud.importObject("j-orders-refund", {customUI: true})
					refund.setOrdersRefund(orderNo,'后台取消',false).then(res=>{
						uni.hideLoading()
						this.$nextTick(() => {
							this.$refs.udb.loadData()
						})
						if(res.code === 200)return uni.showToast({title:res.error,icon:"none"})
						else return uni.showToast({title:res.error,icon:"none"})
					})
					const ordersStatus = await global.getDataOne("orders", {order_no: orderNo}, "status,address,rider,provider")
					const out_trade_no = await db.collection('uni-pay-orders').where({order_no: orderNo,status: 1 }).field('_id,order_no,out_trade_no').get({getOne: true,customUI: true})
					if(out_trade_no.result.affectedDocs > 0 &&ordersStatus.data.provider.value != 'yue'){
						this.$refs.pay.refund({
							out_trade_no: out_trade_no.result.data.out_trade_no, // 插件支付单号
							refund_desc: '订单号' + orderNo + '退款金额已到账'
						})
					}
				})
				
			},
			// 状态更换
			updateStatus(){
				let orderNo = 	this.temp_uid.order_no
				let status = this.rangeStatus[this.selectStatus===9?6:this.selectStatus]
				let payDate = 	this.temp_uid.pay_date
				let createDate = 	this.temp_uid.create_date.time_stamp
				updateStatus(orderNo,status,payDate,createDate).then(result => {
					console.log(result);
					this.$refs.showUpdateStatus.close()
					if (result.code === 200)
						return uni.showToast({title:"状态修改成功"}).then(()=>{
							this.$nextTick(() => { this.$refs.udb.loadData() })
						})
				})
			},
			// 骑手选择
			handleItemClick(item,index){
				this.selectRider = index
				let tempRider = this.rangeRider[this.selectRider]
			},
			// 更换骑手
			updateRider(){
				this.$refs.showUpdateRider.close()
				let orderNo = 	this.temp_uid.order_no
				let tempRider = this.rangeRider[this.selectRider]
				let money = this.temp_uid.deduct_delivery_price
				let currentRiderId = this.temp_uid.rider?this.temp_uid.rider.user_id : null
				updateRider(orderNo,tempRider,money,currentRiderId).then(result => {
					if (result.code === 200)
						return uni.showToast({title:"更换成功"}).then(()=>{
							this.getRider()
							this.$nextTick(() => { this.$refs.udb.loadData() })
						})
					else
						return uni.showModal({
							title:"更换失败",
							content:result.error
						})
				})
			},
			onOpention(item, index) {
				if (index === 1) {
					this.temp_uid = item[0].tel
					this.$refs.showStatus.open()
				} else if (index === 2) {
					// 退款
					this.temp_uid = item
					this.$refs.showOrderOut.open()
				}
				else if(index === 3){
					this.temp_uid = item
					this.$refs.showUpdateRider.open()
				}
				else if (index === 4) {
					this.temp_uid = item
					this.selectStatus = item.status.value
					
					this.$refs.showUpdateStatus.open()
				}
				// console.log(this.temp_uid);
			},
			onqueryload(data) {
				// console.log(data);
				this.exportExcelData = data
			},
			isPower(admin=['']){
				return  Util.userHasPermission(admin)
			},
			loadData(clear = true) {
				this.$refs.udb.loadData({
					clear
				})
			},
			onPageChanged(e) {
				this.selectedIndexs.length = 0
				this.$refs.table.clearSelection()
				this.$refs.udb.loadData({
					current: e.current
				})
			},
			navigateTo(url, clear) {
				// clear 表示刷新列表时是否清除页码，true 表示刷新并回到列表第 1 页，默认为 true
				uni.navigateTo({
					url,
					events: {
						refreshData: () => {
							this.loadData(clear)
						}
					}
				})
			},
			IsAdddress(address){
				if (address)
					if (typeof address.name === 'undefined')	return false
					else	return true
				else 	return false
			},
			mobileReconfiguration(mobile) {
				return Util.formatPhoneNumber(mobile)
			},
			// 日期更换
			datetimePicker(e){
				if(e.length > 0){
					this.startTime = e[0]
					this.endTime = e[1]
				}else{
					this.startTime = Util.getDayTimestamps(0).startTime
					this.endTime = Util.getDayTimestamps(0).endTime
				}
				this.updateDateWhere()
			},
			// 下拉框
			changeDateSelect(e) {
				if (e == 0) {
					this.startTime = Util.getDayTimestamps(e).startTime
					this.endTime = Util.getDayTimestamps(e).endTime
				} else if (e == 1) {
					this.startTime = Util.getStartAndEndTimestamp(1).startTime
					this.endTime = Util.getStartAndEndTimestamp(0).startTime
				} else if (e == 2) {
					this.startTime = Util.getStartAndEndTimestamp(6).startTime
					this.endTime = Util.getStartAndEndTimestamp(6).endTime
				} else if (e == 3) {
					this.startTime = Util.getStartAndEndTimestamp(30).startTime
					this.endTime = Util.getStartAndEndTimestamp(30).endTime
				}
				this.selectTimeVal = e
				this.updateDateWhere()
			},
			updateDateWhere(){
				if (where_uid) {
					this.orderWhere = {
						"create_date.time_stamp": db.command.gt(this.startTime).and(db.command.lt(this.endTime)),
						"shop_id": where_uid,
						"status.value": this.orderWhere["status.value"],
						"$and": this.orderWhere.$and,
						"shop_id.area_all.value":this.orderWhere["shop_id.area_all.value"],
					}
				} else {
					this.orderWhere = {
						"create_date.time_stamp": db.command.gt(this.startTime).and(db.command.lt(this.endTime)),
						"status.value": this.orderWhere["status.value"],
						"$and": this.orderWhere.$and,
						"shop_id.area_all.value":this.orderWhere["shop_id.area_all.value"],
					}
				}
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
			onStatus(Num) {
				return Util.onStatus(Num)
			},
			// 多选处理
			selectedItems() {
				var dataList = this.$refs.udb.dataList
				return this.selectedIndexs.map(i => dataList[i]._id)
			},
			// 批量删除
			delTable() {
				this.$refs.udb.remove(this.selectedItems(), {
					success: (res) => {
						this.$refs.table.clearSelection()
					}
				})
			},
			// 多选
			selectionChange(e) {
				this.selectedIndexs = e.detail.index
			},
			sortChange(e, name) {
				this.orderByFieldName = name;
				if (e.order) {
					this.orderby = name + ' ' + orderByMapping[e.order]
				} else {
					this.orderby = ''
				}
				this.$refs.table.clearSelection()
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
		}
	}
</script>
<style scoped lang="scss">
	.maxbox{
		max-height:500px ;
		overflow: auto;
	}
	.grid{
		padding:0rpx 0 0 0; 
		display:grid;
		grid-template-columns:repeat(auto-fill,minmax(150rpx,1fr) )  ;
		.item_box:hover{
			background-color: #f4f6ff;
			transition:.5s;
		}
		.image{
			width:40px;
		}
		.item_box{
			transition:.5s;
			cursor:pointer;
			margin:8px;
			text-align: center;
			padding:5px 0 0 0;
			border:1px solid #eee;
			border-radius:10px;
			.title{
				font-weight:bold;
				overflow:hidden;
				text-overflow: ellipsis;
				display:-webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}
			.label{
				font-size:14px;
				color:#999;
				overflow:hidden;
				text-overflow: ellipsis;
				display:-webkit-box;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
			}
		}
		.item_boxTow{
			background-color: #f4f6ff;
			border:1px solid #36d;
		}
	}
	.select {
		width: 200rpx;
		margin: 0 20rpx;
	}

	.title {
		font-weight: bold;
		line-height: 70rpx;
	}

	.popup {
		border-radius: 10rpx;
		.body {
			padding: 0 0 0 20rpx;
		}
		width:500px;
		min-height:200px;
		padding:30rpx;
		button {
			margin: 0 50rpx;
		}
	}
</style>